<!DOCTYPE html>
<html>
<head>
    <script type='text/javascript' src="./cordova.js"></script>
    <script type='text/javascript' src="./cordova_plugins.js"></script>
</head>

<body>
<div>
    <input id="src_string" value="input a string to encrypt"/>
    <br/>

    <label for="encrypt_result">encrypt result</label>

    <p id="encrypt_result"></p>
    <label for="decrypt_result">decrypt result</label>

    <p id="decrypt_result"></p>

</div>
<button id="test">test</button>
<br/>
<button id="encrypt_string">encrypt_string</button>
<br/>
<button id="decrypt_string">decrypt_string</button>
<br/>

<div>
    <p>src file : /mnt/sdcard/crypt_src.txt</p>

    <p>dst file : /mnt/sdcard/crypt_dst.txt</p>
</div>
<button id="encrypt_file">encrypt_file</button>
<br/>
<button id="decrypt_file">decrypt_file</button>
<br/>

<script type="text/javascript">
    //
    document.getElementById('test').onclick = function () {
        console.log('click test');
    }

    // 加密string
    document.getElementById('encrypt_string').onclick = function () {
        'use strict'
        var str = document.getElementById('src_string').value;
        cordova.exec(function (retVal) {
            console.log('call encrypt success');
            console.log('retVal=' + retVal.toString());
            document.getElementById('encrypt_result').innerHTML = retVal;
        }, function (retVal) {
            console.log('call encrypt fail');
            console.log('retVal=' + retVal.toString());
            document.getElementById('encrypt_result').innerHTML = '加密失败';
        }, "Crypt", 'encrypt', str);
    };

    // 解密string
    document.getElementById('decrypt_string').onclick = function () {
        'use strict'
        var str = document.getElementById('encrypt_result').innerHTML;
        if (!str) {
            alert('empty string');
            return;
        }
        cordova.exec(function (retVal) {
            console.log('call encrypt success');
            console.log('retVal=' + retVal.toString());
            document.getElementById('decrypt_result').innerHTML = retVal;
        }, function (retVal) {
            console.log('call encrypt fail');
            console.log('retVal=' + retVal.toString());
            document.getElementById('decrypt_result').innerHTML = "解密失败";
        }, "Crypt", 'decrypt', str);
    };

    // 加密文件
    document.getElementById('encrypt_file').onclick = function () {
        'use strict'
        cordova.exec(function () {
                    console.log('succ');
                }, function (err) {
                    console.log(err);
                }, "Crypt", "encrypt",
                [
                    {src: "sdcard/crypt_src.txt"},
                    {dst: "sdcard/crypt_dst.txt"}
                ]);
    }
    // 解密文件
    document.getElementById('decrypt_file').onclick = function () {
        'use strict'
        cordova.exec(function () {
                    console.log('succ');
                }, function (err) {
                    console.log(err);
                }, "Crypt", "decrypt",
                [
                    {src: "sdcard/crypt_dst.txt"},
                    {dst: "sdcard/crypt_check.txt"}
                ]);
    }
</script>
</body>
</html>